package com.broad.school_description.contoller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

//@RestController
public class KafkaController {

    @Autowired
    KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/get/kafka/{message}")
    public String getRest(@PathVariable("message") String message){
        for (int i = 0; i < 1000; i++) {
            kafkaTemplate.send("test",message);
            final KafkaTemplate<String,String> kafkaTemplate2 = kafkaTemplate;
            final String msg = message;
            for (int j = 0; j < 10; j++)
            new Thread(new Runnable() {
                @Override
                public void run() {
                    kafkaTemplate2.send("springboottopic", msg);
                }
            }).start();
        }



        return "ok";
    }
}
